import { getStageBydialogIdAndNodeId,saveStageBydialogIdAndNodeId,getDialogInquire,getUserAllDict,getCoreWordById} from '@/services/dialog';
import { fetchApiListById,slotList} from '@/services/basiccapacity';

export default {
  namespace: 'collectSlot',
  state: {
    total: null,
    data: [],
    loading: false
  },

  effects: {

    *fetchSlot({payload,callback}, { call, put }) {
      const response = yield call(getStageBydialogIdAndNodeId,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *saveSlot({payload,callback}, { call, put }) {
      const response = yield call(saveStageBydialogIdAndNodeId,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getInquire({payload,callback}, { call, put }) {
      const response = yield call(getDialogInquire,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getAllDict({payload,callback}, { call, put }) {
      const response = yield call(getUserAllDict,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getSlotInfo({payload,callback}, { call, put }) {
      const response = yield call(getCoreWordById,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    }
  }
};
